package com.example.demo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.Interface.OnCustomCityPickerItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.CustomCityData;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.citywheel.CityConfig;
import com.lljjcoder.citywheel.CustomConfig;
import com.lljjcoder.style.citycustome.CustomCityPicker;
import com.lljjcoder.style.cityjd.JDCityConfig;
import com.lljjcoder.style.cityjd.JDCityPicker;
import com.lljjcoder.style.citypickerview.CityPickerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    // ios样式
    private CityPickerView CityPicker = new CityPickerView();

    // 京东样式
    private JDCityPicker jdCityPicker = new JDCityPicker();

    private CustomCityPicker customCityPicker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ios();
        jd();
        custom();

    }

    private void ios() {
        // 预先加载数据
        CityPicker.init(this);

        // 配置
        /*CityConfig cityConfig = new CityConfig.Builder()
                .title("选择城市")//标题
                .titleTextSize(18)//标题文字大小
                .titleTextColor("#585858")//标题文字颜  色
                .titleBackgroundColor("#E9E9E9")//标题栏背景色
                .confirTextColor("#585858")//确认按钮文字颜色
                .confirmText("ok")//确认按钮文字
                .confirmTextSize(16)//确认按钮文字大小
                .cancelTextColor("#585858")//取消按钮文字颜色
                .cancelText("cancel")//取消按钮文字
                .cancelTextSize(16)//取消按钮文字大小
                //显示类，只显示省份一级，显示省市两级还是显示省市区三级
                .setCityWheelType(CityConfig.WheelType.PRO_CITY_DIS)
                .showBackground(true)//是否显示半透明背景
                .visibleItemsCount(7)//显示item的数量
                .province("浙江省")//默认显示的省份
                .city("杭州市")//默认显示省份下面的城市
                .district("滨江区")//默认显示省市下面的区县数据
                .provinceCyclic(true)//省份滚轮是否可以循环滚动
                .cityCyclic(true)//城市滚轮是否可以循环滚动
                .districtCyclic(true)//区县滚轮是否循环滚动
                .setCustomItemLayout(R.layout.item_city)//自定义item的布局
                //自定义item布局里面的textViewid
                .setCustomItemTextViewId(R.id.item_city_name_tv)
                .drawShadows(false)//滚轮不显示模糊效果
                .setLineColor("#03a9f4")//中间横线的颜色
                .setLineHeigh(5)//中间横线的高度
                .setShowGAT(true)//是否显示港澳台数据，默认不显示
                .build();*/
        CityConfig cityConfig = new CityConfig.Builder().build();
        CityPicker.setConfig(cityConfig);

        CityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
            @Override
            public void onSelected(ProvinceBean province,
                                   CityBean city, DistrictBean district) {
                Log.d(TAG, "选择：" + province + "," + city + "," + district);
            }
            @Override
            public void onCancel() {
                Log.d(TAG, "取消");
            }
        });

        findViewById(R.id.button1).setOnClickListener(v -> {
            CityPicker.showCityPicker();
        });
    }

    private void jd() {
        // 预先加载数据
        jdCityPicker.init(this);

        // 京东配置
        JDCityConfig jdCityConfig = new JDCityConfig.Builder()
                .build();
        jdCityPicker.setConfig(jdCityConfig);

        jdCityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
            @Override
            public void onSelected(ProvinceBean province,
                                   CityBean city, DistrictBean district) {
                Log.d(TAG, "选择：" + province + "," + city + "," + district);
            }
            @Override
            public void onCancel() {
                Log.d(TAG, "取消");
            }
        });

        findViewById(R.id.button2).setOnClickListener(v -> {
            jdCityPicker.showCityPicker();
        });
    }

    private void custom() {
        customCityPicker = new CustomCityPicker(this);
        /*
        这个CustomCityData是
        private String id;
        private String name;
        private List<CustomCityData> list = new ArrayList<>();
         */
        List<CustomCityData> data = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            CustomCityData province = new CustomCityData("" + (i * 10000), "省" + i);
            ArrayList<CustomCityData> cities = new ArrayList<>();
            for (int j = 0; j < 10; j++) {
                cities.add(new CustomCityData("" + (i * 10000 + j), province.getName() + "市" + j));
            }
            province.setList(cities);
            data.add(province);
        }

        CustomConfig customConfig = new CustomConfig.Builder()
                .title("选择城市")
                .setCityWheelType(CustomConfig.WheelType.PRO_CITY)
                .setCityData(data)  // 设置数据源
                .provinceCyclic(false)
                .cityCyclic(false)
                .setCustomItemLayout(R.layout.item_city)
                .setCustomItemTextViewId(R.id.item_city_name_tv)
                .build();

        /*
                .title("选择城市")//标题
   		        .setCityData(List<CustomCityData> data)//自定义数据源
                .titleTextSize(18)//标题文字大小
                .titleTextColor("#585858")//标题文字颜  色
                .titleBackgroundColor("#E9E9E9")//标题栏背景色
                .confirTextColor("#585858")//确认按钮文字颜色
                .confirmText("ok")//确认按钮文字
                .confirmTextSize(16)//确认按钮文字大小
                .cancelTextColor("#585858")//取消按钮文字颜色
                .cancelText("cancel")//取消按钮文字
                .cancelTextSize(16)//取消按钮文字大小
                .showBackground(true)//是否显示半透明背景
                .visibleItemsCount(7)//显示item的数量
                .province("**")//设置默认省份
                .city("**")//设置默认城市
                .district("**")//设置默认地区
                .provinceCyclic(true)//省份滚轮是否可以循环滚动
                .cityCyclic(true)//城市滚轮是否可以循环滚动
                .districtCyclic(true)//区县滚轮是否循环滚动
                .setCustomItemLayout(R.layout.item_custome_city)//自定义item的布局
                .setCustomItemTextViewId(R.id.item_custome_city_name_tv)
                .drawShadows(false)//滚轮不显示模糊效果
                .setLineColor("#03a9f4")//中间横线的颜色
                .setLineHeigh(5)//中间横线的高度
                .setCityWheelType(CustomConfig.WheelType.PRO_CITY_DIS)//设置显示省市区还是省市或者省级滚轮
         */

        customCityPicker.setCustomConfig(customConfig);
        customCityPicker.setOnCustomCityPickerItemClickListener(new OnCustomCityPickerItemClickListener() {
            @Override
            public void onSelected(CustomCityData province, CustomCityData city, CustomCityData district) {
                Log.d(TAG, "选择：" + province + "," + city + "," + district);
            }
        });


        findViewById(R.id.button3).setOnClickListener(v -> {
            customCityPicker.showCityPicker();
        });
    }

}